﻿
using Prism.Commands;
using Prism.Services.Dialogs;

namespace LeaderCCSLaserUI.ViewModels.Dialogs
{
    public class PasswordDialogViewModel : DialogViewModel
    {
        private string password = "";
        public string Password
        {
            get { return password; }
            set { SetProperty(ref password, value); }
        }
        private DelegateCommand<object>? passwordOperateCommad;
        public DelegateCommand<object>? PasswordOperateCommad =>
            passwordOperateCommad ?? (passwordOperateCommad = new DelegateCommand<object>(ExecutePasswordOperateCommad));

        void ExecutePasswordOperateCommad(object obj)
        {
            switch (obj.ToString())
            {
                case "确认":
                    OnRequestClose(new DialogResult(Password == GetPassWord() ? ButtonResult.Yes : ButtonResult.No));
                    break;
                case "取消":
                    OnRequestClose(new DialogResult(ButtonResult.No));
                    break;
                default:
                    break;
            }
        }
        public override void OnDialogOpened(IDialogParameters parameters)
        {
            string title = parameters.GetValue<string>("Title");
            Title = title;
        }
        public PasswordDialogViewModel(IContainerProvider containerProvider) : base(containerProvider)
        {
            
        }
        private string GetPassWord()
        {
            int day = System.DateTime.Now.Day;
            int month = System.DateTime.Now.Month;
            string ss = (day + month).ToString();
            string passwordstr = "";
            for (int i = 0; i < 4 - ss.Length; i++)
            {
                passwordstr += "0";
            }
            passwordstr += ss;
            return passwordstr;
        }
    }
}
